package com.zerosky.crm.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.zerosky.crm.dao.SharingRecordsDAO;
import com.zerosky.crm.po.SharingRecords;
import com.zerosky.crm.service.SharingRecordsService;
import com.zerosky.crm.util.PageInfo;

/**
 * SharingRecords业务逻辑实现类
 * 
 * @author 周正祥;
 * @since 2017-07-13
 *
 */
@Service(value="sharingRecordsService")
public class SharingRecordsServiceImpl implements SharingRecordsService {

	@Autowired
	private SharingRecordsDAO sharingRecordsDAO; // SharingRecords数据接口

	/**
	 * SharingRecords列表
	 * 
	 * @author 钟璟;
	 * @since 2017-07-13
	 */
	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public PageInfo<SharingRecords> getSharingRecordsList(Map<String, Object> map) {
		PageInfo<SharingRecords> page = new PageInfo<SharingRecords>();
		if (map.get("page") != null && map.get("pageSize") != null) {
			int begin = (((int) map.get("page") - 1) * (int) map.get("pageSize"));
			// 写入数据
			map.put("pageNo", begin);
		}
		List<SharingRecords> list = sharingRecordsDAO.getSharingRecordsList(map);
		page.setList(list);

		int count = sharingRecordsDAO.getSharingRecordsListCount(map);// 获取总记录
		page.setPageCount(count);
		return page;
	}

	/**
	 * 员工分享次数列表
	 * 
	 * @author 钟璟;
	 * @since 2017-07-13
	 */
	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public PageInfo<SharingRecords> getEmployeeRecordsList(Map<String, Object> map) {
		PageInfo<SharingRecords> page = new PageInfo<SharingRecords>();
		if (map.get("page") != null && map.get("pageSize") != null) {
			int begin = (((int) map.get("page") - 1) * (int) map.get("pageSize"));
			// 写入数据
			map.put("pageNo", begin);
		}
		List<SharingRecords> list = sharingRecordsDAO.getEmployeeRecordsList(map);
		page.setList(list);

		int count = sharingRecordsDAO.getEmployeeRecordsListCount(map);// 获取总记录
		page.setPageCount(count);
		return page;
	}

	/**
	 * 通过主键查找SharingRecords实体
	 * 
	 * @param id
	 *            SharingRecords主键
	 * @author 钟璟;
	 * @since 2017-07-13
	 */
	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public SharingRecords getSharingRecordsById(String id) {
		return sharingRecordsDAO.getSharingRecordsById(id);
	}

	/**
	 * 保存SharingRecords
	 * 
	 * @param SharingRecords
	 *            实体对象, operation 操作类型
	 * @author 钟璟;
	 * @since 2017-07-13
	 */
	@Transactional(propagation = Propagation.REQUIRED) // 创建一个事务，如果有则加入事务
	public void saveSharingRecords(SharingRecords SharingRecords, String operation) {
		if ("新增".equalsIgnoreCase(operation)) {
			sharingRecordsDAO.addSharingRecords(SharingRecords);
		} else if ("修改".equalsIgnoreCase(operation)) {
			sharingRecordsDAO.updateSharingRecords(SharingRecords);
		}

	}

	/**
	 * 删除SharingRecords
	 * 
	 * @param idArray
	 *            SharingRecords主键数组
	 * @author 钟璟;
	 * @since 2017-07-13
	 */
	@Transactional(propagation = Propagation.REQUIRED) // 创建一个事务，如果有则加入事务
	public void deleteSharingRecordsById(String customerId) {
		sharingRecordsDAO.deleteSharingRecordsById(customerId);

	}

}
